#ifndef __SDL_FRAME_HPP
#define __SDL_FRAME_HPP

#include <list>

#include "sdldefs.h"
#include "SDL.h"
#include "sdlevent.hpp"

// a standard frame class.  Each frame has its own screen.
class sdlFrame : public sdlEvent
{
private:
    bool running;

protected:
    std::list<sdlEvent *> evtList;
    SDL_Surface *screen;
public:
    sdlFrame( int width=sdlDefaultWidth, int height=sdlDefaultHeight )
    {
        // Attempt to create a width x height window with 32bit pixels.
        screen = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE);

        // If we fail, return error.
        if ( screen == NULL ){
          fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
          exit(1);
        }
        // Register SDL_Quit to be called at exit; makes sure things are
        // cleaned up when we quit.
        atexit(SDL_Quit);

        running = false;
    }

    ~sdlFrame()
    {
    }

    void init()
    {
        running = true;
        SDL_Event event;

        while(running)
        {
            // Poll for events, and handle the ones we care about.
            while (SDL_PollEvent(&event))
            {
                std::list<sdlEvent *>::iterator iter = evtList.begin();
                for(; iter != evtList.end(); ++iter )
                    (*iter)->update(event);
                fprintf(stderr, "Hello World");
                switch (event.type)
                {
                  case SDL_QUIT:
                    running = false;
                }
            }
        }
    }

    // closes the frame.  As of now, this just stops the init loop.
    void close()
    {
        running = false;
    }
};

#endif // SDL_FRAME_HPP
